package com.image.androidimagebroswer.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.image.androidimagebroswer.adapter.BigImageAdapter;
import com.image.androidimagebroswer.data.MediaData;
import com.image.androidimagebroswer.R;

import java.util.List;

/**
 * Created by liuzhao.futrue on 2018/8/26.
 */

public class BigImageActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {

    private TextView mTextView;
    private List<String> mPathList;
    private ViewPager mPager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        // 数据相关
        mPathList = MediaData.getPhotoList();
        int index = getIntent().getIntExtra("index", 0);

        // Layout相关
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bigimage);
        mTextView = findViewById(R.id.tv_bigimage_index);
        mPager = findViewById(R.id.vp_bigimage);

        // 关于Adapter的处理
        dealAdapter(index);
    }

    private void dealAdapter(int index) {
        BigImageAdapter adapter = new BigImageAdapter(BigImageActivity.this, mPathList);
        mPager.setAdapter(adapter);
        mPager.setCurrentItem(index);
        mTextView.setText((index + 1) + "/" + mPathList.size());
        mPager.addOnPageChangeListener(this);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPager.removeOnPageChangeListener(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        mTextView.setText((position + 1) + "/" + mPathList.size());
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
